<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Title</title>
</head>
<body>
<button onclick="ajaxTest()">测试</button>
<button onclick="ajaxTest02()">测试02</button>
<button onclick="ajaxTest03()">测试03</button>


<script>
    function ajaxTest03(){
        console.log("ajaxTest");
        let path = "@{/emp/test33}";
        let data = {
                "response": {"status": "SUCCESS",
                "data": {
                    "mxRecords": [
                        {
                            "value": "us2.mx3.mailhostbox.com.",
                            "ttl": 1,
                            "priority": 100,
                            "hostName": "@"
                        },
                        {
                            "value": "us2.mx1.mailhostbox.com.",
                            "ttl": 1,
                            "priority": 100,
                            "hostName": "@"
                        },
                        {
                            "value": "us2.mx2.mailhostbox.com.",
                            "ttl": 1,
                            "priority": 100,
                            "hostName": "@"
                        }
                    ],
                    "cnameRecords": [
                        {
                            "aliasHost": "pop.a.co.uk.",
                            "canonicalHost": "us2.pop.mailhostbox.com."
                        },
                        {
                            "aliasHost": "webmail.a.co.uk.",
                            "canonicalHost": "us2.webmail.mailhostbox.com."
                        },
                        {
                            "aliasHost": "smtp.a.co.uk.",
                            "canonicalHost": "us2.smtp.mailhostbox.com."
                        },
                        {
                            "aliasHost": "imap.a.co.uk.",
                            "canonicalHost": "us2.imap.mailhostbox.com."
                        }
                    ],
                    "dkimTxtRecord": {
                        "domainname": "20a19._domainkey.a.co.uk",
                        "value": "\"v=DKIM1; g=*; k=rsa; p=DkfbhO8Oyy0E1WyUWwIDAQAB\"",
                        "ttl": 1
                    },
                    "spfTxtRecord": {
                        "domainname": "a.co.uk",
                        "value": "\"v=spf1 redirect=_spf.mailhostbox.com\"",
                        "ttl": 1
                    },
                    "loginUrl": "us2.cp.mailhostbox.com"
                }
            }
        };
        // console.log("请求测试数据：：："+JSON.stringify(data));
        //ajax code
        $.ajax({
            type:"post",//请求类型get/put/delete
            url:path,//请求地址
            data:JSON.stringify(data),//data 请求参数
            dataType:"json",//返回数据类型
            contentType:"application/json;charset=utf-8",//输入类型
            success:function (data){
                console.log("success");
            },
            error:function (){
                console.log("失败");
            }
        });
    }



    function ajaxTest(){
        console.log("ajaxTest");
        let path = "${pageContext.request.contextPath}/emp/test22";
        let data = {"name":"abc","email":"123@qq.com"};
        //ajax code
        $.ajax({
            type:"post",//请求类型get/put/delete
            url:path,//请求地址
            data:JSON.stringify(data),//data 请求参数
            dataType:"json",//返回数据类型
            contentType:"application/json;charset=utf-8",//输入类型
            success:function (data){
                console.log("success");
                console.log("name:::"+data.name);
                console.log("email:::"+data.email);
            },
            error:function (){
                console.log("失败");
            }
        });
    }


    function ajaxTest02(){
        console.log("ajaxTest");
        let path = "${pageContext.request.contextPath}/emp/test22";
        let data = {
            "company_name": "北工商",
            "level": 99,
            "age": 18,
            "dept": [
                {
                    "name": "邓婕",
                    "sex": "女",
                    "email": "zhenjie@123.com",
                    "url": "./img/3.jpg"
                },
                {
                    "name": "张国立",
                    "sex": "男",
                    "email": "zhangguoli@123.com",
                    "url": "./img/4.jpg"
                },
                {
                    "name": "张铁林",
                    "sex": "男",
                    "email": "zhangtieli@123.com",
                    "url": "./img/5.jpg"
                }
            ]
        };
        console.log("请求测试数据：：："+JSON.stringify(data));
        //ajax code
        $.ajax({
            type:"post",//请求类型get/put/delete
            url:path,//请求地址
            data:JSON.stringify(data),//data 请求参数
            dataType:"json",//返回数据类型
            contentType:"application/json;charset=utf-8",//输入类型
            success:function (data){
                console.log("success");
            },
            error:function (){
                console.log("失败");
            }
        });
    }




    "页面加载JS的几种方式:"
        // window.onload = function (){}; --js
        //onload是window窗口对象的事件属性,语句是把“匿名函数”赋值给window的onload事件属性,当window加载完成时会触发onload事件也就触发了“匿名函数”,执行函数体内的语句

        // $(window).load(function (){}); --Jquery
        //是在页面所有元素(包括html标签以及引用到得所有图片,Flash等媒体)加载完毕后执行的,会遇到页面还没完全加载完用户已经在操作页面

        // $(document).ready(function (){});  --Jquery  简写为$(function(){})!!!   页面的dom元素(Document Object Model)加载完毕后执行,无需等到图片或其他媒体下载
        // $(function (){}); --Jquery

        // body的onload属性   <body onload="text()"></body>    不能够做到js和html完全分离

    // 5.<html>
    // <body onload="load();">
    //     </body>
    // </html>


    function text2(){
        console.log("This is window.onload");
    }
    //用window.onload调用text2
    window.onload = text2;

    //1. window.onload = function (){}; --js
    window.onload = function (){
        text2();
    }




    let OText = {
        "sites":{
            "id":"1",
            "name":"张晨曦",
            "url":"www.baidu.com",
            "lang":{
                "aa":"false",
                "bb":"true"
            }
        }
    }
    // console.log(OText.sites.id+"   "+OText.sites.name+"    "+OText.sites.lang.bb);

    let aaa = [["111","222","333"],["444","555","666"]]
    // console.log(aaa[0][1]);


    let  abc = [];
    for (let i=0;i<10;i++){
        abc[i]=[];
        for (let j = 0; j < 5; j++) {
            abc[i][j]=i+j;
        }
    }
    // console.log(abc);

    var obj = {
        "name": "feiyue",
        "level": 99,
        "age": 18,
        "skillList": [
        {
            "id": 1,
            "name": "天下无双",
            "damage": "123"
        },
        {
            "id": 2,
            "name": "雌雄难辨",
            "damage": "182"
        },
        {
            "id": 3,
            "name": "暗流涌动",
            "damage": "89"
        }
    ]
    };
    for (let i = 0;i<obj.skillList.length;i++){
        if (obj.skillList[i].id==2){
            console.log("id:::"+obj.skillList[i].damage,"name:::"+obj.skillList[i].name);
        }
    }


    let obj2 = {
        "company_name": "北工商",
        "level": 99,
        "age": 18,
        "dept": [
        {
            "name": "邓婕",
            "sex": "女",
            "email": "zhenjie@123.com",
            "url": "./img/3.jpg"
        },
        {
            "name": "张国立",
            "sex": "男",
            "email": "zhangguoli@123.com",
            "url": "./img/4.jpg"
        },
        {
            "name": "张铁林",
            "sex": "男",
            "email": "zhangtieli@123.com",
            "url": "./img/5.jpg"
        }
    ]
    }

    for (let i = 0; i < obj2.dept.length; i++) {
        if (obj2.dept[i].sex=="男"){
            console.log(obj2.dept[i]);
        }
    }



    function funSum(a,b){
        console.log("sum:::"+(a+b));
    }

    function funSumReturn(q,r){
        return (q+r);
    }

    $(function(){
        console.log("页面加载时,自动执行");
        funSum(6,8);
        let aa = 8;//true与数字相加时  true为1   false与数字相加   false为0
        let bb = 5;
        funSum(aa,bb);
        console.log("funSumReturn:::"+funSumReturn(45,67));
    })



</script>
</body>
</html>
